import { S3 } from '@aws-sdk/client-s3'
import { Cloud } from 'laf-client-sdk'

const APPID = 'su75ks' // Laf 应用 appid

const cloud = new Cloud({
  baseUrl: `https://${APPID}.laf.run`,
  getAccessToken: () => '',
})

// 获取云存储临时令牌
const { credentials, endpoint, region } = await cloud.invoke('get-oss-sts')

const s3Client = new S3({
  endpoint: endpoint,
  region: region,
  credentials: {
    accessKeyId: credentials.AccessKeyId,
    secretAccessKey: credentials.SecretAccessKey,
    sessionToken: credentials.SessionToken,
    expiration: credentials.Expiration,
  },
  forcePathStyle: true,
})

export default s3Client
